package com.example.wwk.graduationpractice.Activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.example.wwk.graduationpractice.Globalutils.ActivityCollector;
import com.example.wwk.graduationpractice.R;
import com.example.wwk.graduationpractice.Adapter.SettingAdapter;
import com.example.wwk.graduationpractice.Bean.SettingBean;
import com.example.wwk.graduationpractice.Globalutils.DividerItemDecorationUtils;

import java.util.ArrayList;
import java.util.List;

public class SettingsActivity extends AppCompatActivity implements View.OnClickListener {
    //back
    private ImageView back;
    //RecyclerView
    private List<SettingBean> mList = new ArrayList<>();
    private RecyclerView mRecyclerView;
    private SettingAdapter adapter;
    //intent传值
    private String userName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings_activity);
        ActivityCollector.addActivity(this);
        //绑定

        //back
        back = (ImageView) findViewById(R.id.back);
        back.setOnClickListener(this);
        //intent
        Intent intent = getIntent();
        userName = intent.getStringExtra("thisuserName");
        //初始化列表数据，设置具有功能
        initSettings();
        //RecyclerView
        mRecyclerView = (RecyclerView) findViewById(R.id.setting_recycler_view);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.addItemDecoration(new DividerItemDecorationUtils(this, layoutManager.getOrientation()));
        adapter = new SettingAdapter(mList, userName);
        mRecyclerView.setAdapter(adapter);
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityCollector.removeActivity(this);
    }

    /*
    初始化列表数据，设置具有功能
    */
    private void initSettings() {
        SettingBean settingBean1 = new SettingBean(SettingBean.setting1);
        mList.add(settingBean1);
        SettingBean settingBean2 = new SettingBean(SettingBean.setting2);
        mList.add(settingBean2);
        SettingBean settingBean3 = new SettingBean(SettingBean.setting3);
        mList.add(settingBean3);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
        }

    }
}
